#!/usr/bin/env groovy

import jenkins.model.*
import hudson.PluginManager
import java.util.logging.Logger

def logger = Logger.getLogger("")
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()

// 推荐插件列表
def plugins = [
    'pipeline-stage-view',
    'workflow-aggregator',
    'git',
    'github',
    'docker-workflow',
    'blueocean',
    'credentials-binding',
    'configuration-as-code',
    'locale',
    'timestamper',
    'ws-cleanup',
    'build-timeout',
    'ant',
    'maven-plugin',
    'gradle',
    'allure-jenkins-plugin',
    'htmlpublisher',
    'email-ext'
]

logger.info("开始安装推荐插件...")

plugins.each { plugin ->
    if (!pm.getPlugin(plugin)) {
        logger.info("安装插件: ${plugin}")
        pm.updateCenter.getPlugin(plugin).deploy(true)
    } else {
        logger.info("插件 ${plugin} 已安装")
    }
}

logger.info("插件安装完成！")